import os
import time

import pytest
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from subprocess import call
from selenium.webdriver.chrome.service import Service
from common.path import REPORT_JSON, REPORT_HTML
from config.conf import ConfigManager
from page.ufm_pages.ufm_page import UfmElements
from common.options_chrome import options1




@pytest.fixture(scope="function", autouse=False)
def browser_session(request, driver):
    driver.get(ConfigManager.UFM)

    login(driver)

    yield driver

    logout(driver)

    driver.quit()


def login(driver):
    # 实现登录逻辑
    # driver.get(ConfigManager.UFM)     单独测登录用例需要将这个打开
    login = UfmElements(driver)
    login.username = ConfigManager.username
    login.password = ConfigManager.password
    login.click_login_button()


def logout(driver):
    # 实现登出逻辑
    login = UfmElements(driver)
    login.click_loginout_button()
    login.click_exit_button()
    # time.sleep(2)


@pytest.fixture(scope='function', autouse=False)
def driver():
    service = Service('E:\chromedriver-win64\chromedriver-win64/chromedriver.exe')
    driver = webdriver.Chrome(options=options1(),service=service)
    # driver.get(ConfigManager.UFM)
    driver.maximize_window()
    driver.implicitly_wait(10)
    yield driver
    driver.quit()
